package com.hand.demo.app.service.impl;

import com.hand.demo.app.service.HhrTaSkillsService;
import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import com.hand.demo.app.service.HhrTaJobExpService;
import org.springframework.stereotype.Service;
import com.hand.demo.domain.entity.HhrTaJobExp;
import com.hand.demo.domain.repository.HhrTaJobExpRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 工作经历及实习经历表(HhrTaJobExp)应用服务
 *
 * @author
 * @since 2025-06-16 12:16:53
 */
@Service
public class HhrTaJobExpServiceImpl implements HhrTaJobExpService {
    @Autowired
    private HhrTaJobExpRepository hhrTaJobExpRepository;
    @Autowired
    private HhrTaSkillsService hhrTaSkillsService;

    @Override
    public Page<HhrTaJobExp> selectList(PageRequest pageRequest, HhrTaJobExp hhrTaJobExp) {
        return PageHelper.doPageAndSort(pageRequest, () -> hhrTaJobExpRepository.selectList(hhrTaJobExp));
    }

    @Override
    public void saveData(List<HhrTaJobExp> hhrTaJobExps) {
        List<HhrTaJobExp> insertList = hhrTaJobExps.stream().filter(line -> line.getId() == null).collect(Collectors.toList());
        List<HhrTaJobExp> updateList = hhrTaJobExps.stream().filter(line -> line.getId() != null).collect(Collectors.toList());
        hhrTaJobExpRepository.batchInsertSelective(insertList);
        hhrTaJobExpRepository.batchUpdateByPrimaryKeySelective(updateList);
    }

    @Override
    public void deleteByResumeId(Long resumeId) {
        HhrTaJobExp query = new HhrTaJobExp();
        query.setResumeId(resumeId);
        List<HhrTaJobExp> existingList = hhrTaJobExpRepository.selectList(query);
        if (!existingList.isEmpty()) {
            hhrTaJobExpRepository.batchDeleteByPrimaryKey(existingList);
        }

    }
}

